﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using OpenSoftStore.Client.BLL;
using OpenSoftStore.Client.COL;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Client.SFL;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.BusinessLogic.Money;
using OpenSoftStore.Orm.Model;
using OpenSoftStore.BusinessLogic.Product;
using OpenSoftStore.BusinessLogic.Bill;

namespace OpenSoftStore.Client.UIL.ManageReport
{
    /// <summary>
    /// 对象名称：“欢迎使用”用户控件（用户界面层）
    /// 对象说明：用户进入系统时，用于显时系统相关欢迎信息的模块。
    /// 作者姓名：
    /// 编写日期：
    /// </summary>
    public partial class ReportDefault : UserControl
    {
        private static ReportDefault instance;
        public BillLogic billBll;
        public MoneyLogic moneyBll;
        /// <summary>
        /// 返回一个该控件的实例。如果之前该控件已经被创建，直接返回已创建的控件。
        /// 此处采用单键模式对控件实例进行缓存，避免因界面切换重复创建和销毁对象。
        /// </summary>
        public static ReportDefault Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ReportDefault();
                }
                return instance;
            }
        }

        /// <summary>
        /// 私有的控件实例化方法，创建实例只能通过该控件的Instance属性实现。
        /// </summary>
        private ReportDefault()
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            billBll = new BillLogic();
            moneyBll = new MoneyLogic();
            //GetGrids();

            SPACommon.SetDataGridStyle(dgvBill);
            SPACommon.SetDataGridStyle(dgvProductGroup);
            SPACommon.SetDataGridStyle(dgvMoneyGroup);
        }

        private void GetGrids()
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to = dtpTo.Value.Date;

            string whereStr = string.Format(" where T_Bill.AddTime between #{0}# and #{1}#  ", from, to);
            dgvBill.AutoGenerateColumns = false;
            dgvBill.DataSource = billBll.GetBillReport(whereStr);

            whereStr = string.Format(" where T_Bill.AddTime between #{0}# and #{1}#  ", from, to);
            dgvProductGroup.AutoGenerateColumns = false;
            dgvProductGroup.DataSource = billBll.GetProductGroupReport(whereStr);

            dgvMoneyGroup.AutoGenerateColumns = false;
            whereStr = string.Format(" where T_Money.AddTime between #{0}# and #{1}#  ", from, to);
            dgvMoneyGroup.DataSource = moneyBll.GetMoneyGroupReport(whereStr);
        }        

        internal static void GotoLastPage()
        {
            throw new NotImplementedException();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void glassButton1_Click(object sender, EventArgs e)
        {
            GetGrids();
        }
    }
}
